<template>
  <view class="assessIndex">
    <view class="top">
      <view class="banner">
        <img
          src="https://wanhuhealth.oss-cn-beijing.aliyuncs.com/wanhuhealth-small-program/wanhu-mini-welfare/welfare/images/assessBanner.png"
        />
      </view>
      <view class="tips">
        万户健康数字化智能健康风险评估体系是基于中国人群健康大数据，参考发达国家医疗健康管理系统而开发的数字化管理体系。根据会员的日常生活习惯、体检指标、疾病症状和就医诊疗等信息对会员进行健康风险画像，从而对高风险人群进行提前干预，降低其大病的发生概率。
      </view>
      <view class="tipsDesc">如有体检报告等检查结果，请备好用以填写信息。</view>
      <view class="uni-btn-v">
        <button @click="assessStart">开始评估</button>
      </view>
    </view>
    <view v-if="haveResult" class="history">
      <view class="historyList" @click="lookHistoryAssess">
        <view class="iconLeft"><img :src="iconLeft" /></view>
        查看往期评估报告
        <view class="iconRight"><img :src="iconRight" /></view>
      </view>
    </view>
    <!-- <view class="history">
      <view class="historyList" @click="lookHistoryAssess">
        <view class="iconLeft"><img :src="iconLeft" /></view>
        查看往期评估报告
        <view class="iconRight"><img :src="iconRight" /></view>
      </view>
    </view> -->
    <view class="history">
      <view class="historyList">
        <view class="iconLeft"><img :src="assessDone" /></view>
        完成健康评估的会员数
      </view>
      <view class="assessDoneNum">
        <span v-for="(item, index) in initNums" :key="index">{{ item }}</span>
      </view>
    </view>
  </view>
</template>

<script>
import iconRight from '@/static/icon/right.png';
import assessDone from '@/static/icon/assessDone.png';
import { getAssessDonecount, getAssessResult, getAssessListNow } from '@/api/assessQuestion';
import { mapGetters } from 'vuex';
export default {
  components: {
    // 头部参评人员及进度条组件
  },
  data() {
    return {
      iconLeft:
        'https://wanhuhealth.oss-cn-beijing.aliyuncs.com/wanhuhealth-small-program/wanhu-mini-welfare/welfare/index/hzgs.png',
      iconRight: iconRight,
      assessDone: assessDone,
      patientId: 'aad6bdc443dd4803b0e9cbd7e1c56ab1',
      initNums: [],
      haveResult: false
    };
  },
  computed: {
    ...mapGetters(['assessForm'])
  },
  onLoad: function (option) {
    if (option && option.patientId) {
      this.$store.commit('assessQuestion/SET_ASSESSPATIENTID', option.patientId);
      this.patientId = option.patientId;
    } else {
      this.$store.commit('assessQuestion/SET_ASSESSPATIENTID', 'aad6bdc443dd4803b0e9cbd7e1c56ab1');
      this.patientId = 'aad6bdc443dd4803b0e9cbd7e1c56ab1';
    }
    this.initPageData();
    this.getAssessResultObj();
  },
  mounted() {
    this.getDoneAssessNum();
  },
  methods: {
    initPageData() {
      this.$store.commit('assessQuestion/SET_ACTIVE', 0);
      this.$store.commit('assessQuestion/SET_AJAXRES', false);

      let storeData = this.assessForm;
      Object.keys(storeData).forEach((key) => {
        storeData[key] = '';
      });
      this.$store.commit('assessQuestion/SET_ASSESSFORM', storeData);
    },
    async getDoneAssessNum() {
      let { data: nums } = await getAssessDonecount();
      this.initNums = [];
      nums = JSON.stringify(nums);
      for (let i = 0; i < nums.length; i++) {
        this.initNums.push(nums[i]);
      }
      if (this.initNums.length < 7) {
        for (let i = 6; i >= this.initNums.length; i--) {
          this.initNums.unshift(0);
        }
      }
    },
    async assessStart() {
      this.$store.commit('assessQuestion/SET_ACTIVE', 0);
      this.$store.commit('assessQuestion/SET_AJAXRES', false);
      // const { data: isDoneToday } = await getIsPhysicalExamination(this.patientId, 0);
      // if (isDoneToday) {
      //   uni.showToast({
      //     title: `您今日已经做过评估，如有需要，请明日再来`,
      //     icon: 'none'
      //   });
      //   return false;
      // }
      this.$wxPromise.navigateTo({
        url: '/pagesB/assessSick/assessPage'
      });
    },
    getAssessResultObj() {
      getAssessResult(this.patientId).then((res) => {
        if (res.code === 0 && res.data && res.data.riskResults.length > 0) {
          this.haveResult = true;
        }
      });
      getAssessListNow(this.patientId).then((res) => {
        if (res.code === 0 && res.data && res.data.length > 0 && res.data[0].chronicDisease.riskLevel.level) {
          this.haveResult = true;
        }
      });
    },
    lookHistoryAssess() {
      this.$wxPromise.navigateTo({
        url: `/pagesB/assessSick/assessHistoryListPage?patientId=${this.patientId}`
      });
    },
    lookAssessBtn() {
      this.$wxPromise.navigateTo({
        url: `/pagesB/assessResult/index?patientId=${this.patientId}`
      });
    }
  }
};
</script>
<style>
.uni-btn-v button {
  border: none !important;
}
button:after {
  border: none !important;
}
</style>
<style lang="scss">
.assessIndex {
  margin: 24rpx;
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  .top {
    text-align: center;
    background-color: #fff;
    border-radius: 16rpx;
    padding: 24rpx;
    .banner {
      padding: 24rpx;
      img {
        width: 465rpx;
        height: 352rpx;
      }
    }
    .tips {
      color: rgba(0, 0, 0, 0.55);
      font-size: 32rpx;
      text-align: left;
    }
    .tipsDesc {
      color: rgba(0, 0, 0, 0.35);
      font-size: 28rpx;
      text-align: center;
      margin-top: 60rpx;
    }
    .uni-btn-v {
      text-align: center;
      padding: 20rpx 0 80rpx 0;
      button {
        width: 600rpx;
        height: 88rpx;
        border: 2rpx solid rgba(0, 0, 0, 0);
        background: linear-gradient(236deg, #fe894d 0%, #ef3931 100%);
        opacity: 1;
        border-radius: 44rpx;
        color: #fff;
        font-size: 36rpx;
      }
    }
  }
  .history {
    margin: 34rpx 0;
    background-color: #fff;
    border-radius: 16rpx;
    padding: 24rpx;
    .historyList {
      position: relative;
      padding: 0 50rpx;
      .iconLeft {
        position: absolute;
        left: 0;
        top: 0;
        width: 46rpx;
        height: 46rpx;
        img {
          width: 46rpx;
          height: 46rpx;
        }
      }
      .iconRight {
        position: absolute;
        right: 0;
        top: 0;
        width: 46rpx;
        height: 46rpx;
        img {
          width: 46rpx;
          height: 46rpx;
        }
      }
    }
    .assessDoneNum {
      text-align: center;
      margin: 20rpx;
      span {
        display: inline-block;
        padding: 10rpx;
        width: 48rpx;
        margin: 8rpx;
        background: #f4f4f4;
        color: rgba(243, 78, 28, 1);
      }
    }
  }
}
</style>
